package com.learn.xueer.ui.activity

import android.os.Bundle
import androidx.lifecycle.Observer
import com.google.gson.Gson
import com.learn.xueer.app.base.BaseActivity
import com.learn.xueer.databinding.ActivityMessageBinding
import com.learn.xueer.ui.viewmodel.MessageViewModel
import me.hgj.jetpackmvvm.util.ActivityMessenger

/**
 * 消息
 */
class MessageActivity : BaseActivity<MessageViewModel, ActivityMessageBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewmodel=mViewModel
        mDatabind.click = ProxyClick()
        mViewModel.messageReq()
    }


    override fun createObserver() {
        mViewModel.messageResult.observe(this, Observer {
            if (it.message.isNotEmpty()) {
                mViewModel.messageContent.value = it.message[0].content
                mViewModel.messageTime.value = it.message[0].create_time_text
            }
            if (it.notice.isNotEmpty()) {
                mViewModel.noticeContent.value = it.notice[0].content
                mViewModel.noticeTime.value = it.notice[0].create_time_text
            }

        })
    }

    inner class ProxyClick {
        fun back() {
            finish()
        }

        fun work() {
            ActivityMessenger.startActivity<WorkMessageActivity>(
                this@MessageActivity,
                "data" to Gson().toJson(mViewModel.messageResult.value?.message)
            )
        }

        fun inMess() {
            ActivityMessenger.startActivity<InnerMessageActivity>(
                this@MessageActivity,
                "data" to Gson().toJson(mViewModel.messageResult.value?.notice)
            )
        }

    }
}